import { Injectable } from '@nestjs/common';
import { RoleEntity } from './../../entities/role.entity';

import { InjectRepository } from '@nestjs/typeorm';
import { DeleteResult, Repository, UpdateResult } from 'typeorm';

@Injectable()
export class RoleService {
  @InjectRepository(RoleEntity)
  private readonly roleRepository: Repository<RoleEntity>;

  async createRole(data: RoleEntity): Promise<RoleEntity> {
    return await this.roleRepository.save(data);
  }

  async deleteRoleById(id: number): Promise<DeleteResult> {
    return await this.roleRepository.softDelete(id);
  }

  async updateRoleById(id: number, data: RoleEntity): Promise<UpdateResult> {
    return await this.roleRepository.update(id, data);
  }

  async findRoleList(): Promise<RoleEntity[]> {
    return await this.roleRepository.find();
  }

  async findRoleById(id: number): Promise<RoleEntity> {
    return await this.roleRepository.findOne(id);
  }
}
